// 更新验证码
var $val_code_img = $("#val_code_img");
$val_code_img.attr('src', '/verification/img?r=1&t=' + Date.parse(new Date()));
$val_code_img.click(function () {
    $val_code_img.attr('src', '/verification/img?r=1&t=' + Date.parse(new Date()));
});

var $registerForm = $('#registerForm');

//$.validator.addMethod("customUsername", function (value, element) {
//    if (value === $registerForm.find('input[name="emailAddress"]').val()) {
//        return true;
//    }

//    //Username can not be an email address (except the email address entered)
//    return !$.validator.methods.email.apply(this, arguments);
//}, abp.localization.localize("RegisterFormUserNameInvalidMessage", "CoreMvc"));

var $registerForm = $("#registerForm");

// initialization of form validation
$.HSCore.components.HSValidation.init('.js-validate', {
    rules: {
        confirmPassword: {
            equalTo: '#password'
        }
    }
});

$registerForm.submit(function (e) {
    e.preventDefault();

    if (!$registerForm.valid()) {
        return;
    }

    abp.ui.setBusy(
        null,
        abp.ajax({
            contentType: abp.formex.contentTypeJson,
            url: $registerForm.attr('action'),
            data: JSON.stringify($registerForm.serializeJSON())
        }).done(function (result) {
            window.location.href = result;
        }).fail(function () {
            $val_code_img.click();
        })
    );
});